<template>
<onekit-page>
<onekit-view onekit-class="container">
	<div is="onekit-template-head" :DATA="`${JSON.stringify({title:'get/set/clearStorage'})}`"></div>
	<onekit-view onekit-class="page-body">
		<onekit-view onekit-class="page-section">
			<onekit-view onekit-class="weui-cells weui-cells_after-title">
				<onekit-view onekit-class="weui-cell weui-cell_input">
					<onekit-view onekit-class="weui-cell__hd">
						<onekit-view onekit-class="weui-label">key</onekit-view>
					</onekit-view>
					<onekit-view onekit-class="weui-cell__bd">
						<onekit-input onekit-class="weui-input" type="text" placeholder="请输入key" name="key" :value="key" @Input="keyChange"></onekit-input>
					</onekit-view>
				</onekit-view>
				<onekit-view onekit-class="weui-cell weui-cell_input">
					<onekit-view onekit-class="weui-cell__hd">
						<onekit-view onekit-class="weui-label">value</onekit-view>
					</onekit-view>
					<onekit-view onekit-class="weui-cell__bd">
						<onekit-input onekit-class="weui-input" type="text" placeholder="请输入value" name="data" :value="data" @Input="dataChange"></onekit-input>
					</onekit-view>
				</onekit-view>
			</onekit-view>
			<onekit-view onekit-class="btn-area">
				<onekit-button type="primary" @Tap="setStorage">存储数据</onekit-button>
				<onekit-button @Tap="getStorage">读取数据</onekit-button>
				<onekit-button @Tap="clearStorage">清理数据</onekit-button>
			</onekit-view>
		</onekit-view>
	</onekit-view>
	<div is="onekit-template-foot"></div>
</onekit-view>
</onekit-page></template>
<script>
/* eslint-disable */
import Vue from 'vue';
import onekit_template_0 from '../../../common/head.head.vue';Vue.component('onekit-template-head',onekit_template_0);
import onekit_template_1 from '../../../common/foot.foot.vue';Vue.component('onekit-template-foot',onekit_template_1);
const ONEKIT_JSON= {
  "navigationBarTitleText": "数据存储",
  "usingComponents": {
    
  }
};
const ONEKIT_SJS = {
};
import wx from '../../../../weixin2vue/wx.js';
import Macro from '../../../../weixin2vue/Macro.js';
const {getApp,getCurrentPages} = Macro;
import Page from '../../../../weixin2vue/OnekitPage.js';
import Component from '../../../../weixin2vue/OnekitComponent.js';
export default Page(ONEKIT_JSON,["key","data"],ONEKIT_SJS,{
    "onShareAppMessage"(){
      return {
        "title":'数据存储',
        "path":'packageAPI/pages/storage/storage'
};
    },
    "data":{
        "key":'',
        "data":'',
        "dialog":{
            "title":'',
            "content":'',
            "hidden":true
}
},
    "keyChange"(e){
      this.data.key = e.detail.value;
    },
    "dataChange"(e){
      this.data.data = e.detail.value;
    },
    "getStorage"(){
      const {key,data} = this.data;
      let storageData;
      if(key.length == 0)
      {
        this.setData({
            key,
            data
});
        wx.showModal({
            "title":'读取数据失败',
            "content":'key 不能为空'
});
      }
else
      {
        storageData = wx.getStorageSync(key);
        console.log(storageData);
        if(storageData == '')
          {
            this.setData({
                key,
                "data":storageData
});
            wx.showModal({
                "title":'读取数据失败',
                "content":'找不到 key 对应的数据'
});
          }
else
          {
            this.setData({
                key,
                "data":storageData
});
            wx.showModal({
                "title":'读取数据成功',
                "content":storageData
});
          }
      };
    },
    "setStorage"(){
      const {key,data} = this.data;
      if(key.length == 0)
      {
        this.setData({
            key,
            data
});
        wx.showModal({
            "title":'保存数据失败',
            "content":'key 不能为空'
});
      }
else
      {
        wx.setStorageSync(key,data);
        this.setData({
            key,
            data
});
        wx.showModal({
            "title":'存储数据成功'
});
      };
    },
    "clearStorage"(){
      wx.clearStorageSync();
      this.setData({
        "key":'',
        "data":''
});
      wx.showModal({
        "title":'清除数据成功'
});
    }
});

</script>
<style 
 lang="css">
@import '/common/lib/weui.css';
</style>